<?php
header("Content-Type: text/html; charset=iso-8859-1");
require_once('include.php');
$id = (!empty($_REQUEST['id'])) ? $_REQUEST['id'] : "";
$comment = (!empty($_REQUEST['comment'])) ? $_REQUEST['comment'] : "";
$confirm = (!empty($_REQUEST['confirm'])) ? $_REQUEST['confirm'] : "";
$contenu = (!empty($_REQUEST['contenu'])) ? $_REQUEST['contenu'] : "";
$action = (!empty($_REQUEST['action'])) ? $_REQUEST['action'] : "";
if($action == "edit"){
	if($comment){
		$q = "select contenu, membre_id from commentaires_info where commentaires_info.id = $comment";
		$r = ExecRequete($q);
		$return = "";
		if($s = LigneSuivante($r)){
			if($s->membre_id == check_cookie() || check_admin()){
				$q1 = "update commentaires_info set contenu = '".(addslashes($contenu))."' where id = $comment";
				ExecRequete($q1);
				echo $contenu;
			}
		}
	}
}
elseif($action == 'del'){
	if(!$confirm){
		echo "<p class = 'center'><button type = 'button' name = 'ok' onclick = 'del_comment_ok($comment,1)'>effacer</button><button type = 'button' name = 'ok' onclick = 'del_comment_ok($comment,2)'>annuler</button></p>\n";
	}
	else{
		$q = "select contenu, membre_id, info_id from commentaires_info where commentaires_info.id = $comment";
		$r = ExecRequete($q);
		$return = "";
		if($s = LigneSuivante($r)){
			if($s->membre_id == check_cookie() || check_admin()){
				if($confirm == 1){
					$q1 = "delete from commentaires_info where id = $comment";
					ExecRequete($q1);
					echo $s->info_id;					
				}
				else echo $s->contenu;
			}
			else echo $s->contenu;
		}
		
	}
}
elseif($id){
	$info = new info($id);
	if($action=='form' && $comment){
		$info = new info($id);
		$content = $info->get_commentaire($comment);
		echo "<form action = 'javascript:edit_commentaire($comment,document.form_edit_comment.comment.value)' name = 'form_edit_comment' id = 'form_edit_comment'>\n";
		echo "<p class = 'center'><textarea cols = '60' rows = '10' name = 'comment'>$content</textarea></p>\n";
		echo "<p class = 'center'><button type = 'submit' name = 'modifier' value = '1'>modifier</button></p></form>\n";
	}

	else echo $info->list_commentaires();
}
else echo "";
?>